package com.example.mrzhou.lvmm.view.fragment.surround;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.base.BaseFragment;
import com.example.mrzhou.lvmm.entity.surround.scenic.Scenic;
import com.example.mrzhou.lvmm.entity.surround.scenic.TickListBean;
import com.example.mrzhou.lvmm.presenter.surround.ScenicPresenter;
import com.example.mrzhou.lvmm.view.adapter.surround.ScenicAdapter;
import com.example.mrzhou.lvmm.view.impl.surround.ScenicView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class SurScenicFragment extends BaseFragment implements ScenicView {


    @BindView(R.id.rclv_sur_scenic)
    RecyclerView rclvSurScenic;
    private List<TickListBean> data = new ArrayList<>();
    private ScenicAdapter adapter;
    private static OnScenicCallBack callBack;

    public SurScenicFragment() {
        // Required empty public constructor
    }

    public static SurScenicFragment newInstance(OnScenicCallBack mcallBack) {

        Bundle args = new Bundle();

        SurScenicFragment fragment = new SurScenicFragment();
        fragment.setArguments(args);
        callBack = mcallBack;
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_sur_sample;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
        rclvSurScenic.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new ScenicAdapter(getContext(), data);
        rclvSurScenic.setAdapter(adapter);
        initData();
    }

    @Override
    protected void initData() {
        HashMap<String, String> map = new HashMap<>();
        map.put("pageNum", "1");
        map.put("pageSize", "20");
        map.put("windage", "100");
        map.put("longitude", "116.403625");
        map.put("latitude", "39.913249");
        map.put("sort", "15");
        map.put("searchAround", "true");
        map.put("version", "2.0.0");
        ScenicPresenter presenter = new ScenicPresenter(this);
        presenter.getScenicData(map);
    }

    @Override
    public void onSuccess(Scenic scenic) {
        if (scenic != null) {
            data.addAll(scenic.getData().getTickList());
            adapter.notifyDataSetChanged();
            callBack.onScenicCallBack(scenic);
        }
    }

    @Override
    public void onFaiure(Throwable a) {

    }

    @Override
    public void onFinsh() {

    }

    public interface OnScenicCallBack {
        void onScenicCallBack(Scenic scenic);
    }
}
